package com.hu.zhcc.shiro.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hu.zhcc.shiro.dao.CategoryMapper;
import com.hu.zhcc.shiro.dao.CheckResultMapper;
import com.hu.zhcc.shiro.dao.HMemberofthefileMapper;
import com.hu.zhcc.shiro.dao.TherapyMapper;
import com.hu.zhcc.shiro.entity.bo.Category;
import com.hu.zhcc.shiro.entity.bo.CheckResult;
import com.hu.zhcc.shiro.entity.bo.HMemberofthefile;
import com.hu.zhcc.shiro.entity.bo.Therapy;
import com.hu.zhcc.shiro.entity.vo.CategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService{

    @Autowired
    private CategoryMapper CategoryMapper;
    @Autowired
    private HMemberofthefileMapper hMemberofthefileMapper;
    @Autowired
    private TherapyMapper therapyMapper;

    @Override
    public int insert(Category record) {
        return CategoryMapper.insert(record);
    }

    //分页查询
    @Override
    public PageInfo<Category> pageQuery(CategoryVO CategoryVO) {
        PageHelper.startPage(CategoryVO.getPageNum(),CategoryVO.getPageSize());
        List<Category> byCondition = CategoryMapper.findByCondition(CategoryVO.getQueryString());
        PageInfo<Category> checkItemPageInfo = new PageInfo<>(byCondition);
        return checkItemPageInfo;
    }

    @Override
    public boolean updateCategory(Category Category) {
        Category.setState(0);
        HMemberofthefile byfilename = hMemberofthefileMapper.findByfilename(Category.getFilenumber());
        Therapy therapy = new Therapy();
        therapy.setFilenumber(byfilename.gethFn());
        therapy.setName(byfilename.gethName());
        therapy.setSex(byfilename.gethSex());
        therapy.setAge(Integer.valueOf(byfilename.gethAge()));
        therapy.setPhone(byfilename.gethPhone());
        therapy.setPostbox(null);
        therapy.setFiling(byfilename.gethRegistration());
        therapyMapper.insert(therapy);
        return CategoryMapper.updateByPrimaryKey(Category)>0;
    }

    @Override
    public boolean removeCategory(Short id) {
        return CategoryMapper.deleteByPrimaryKey(id)>0;
    }
}
